package com.yy.micro.magic.data.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yy.micro.magic.data.model.base.JpaObjectWithDynamicFields;
import com.yy.micro.magic.data.model.converter.TypedSetConverter;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
@Proxy(lazy = false)
@Entity
@Table(name = "T_M_CODE_MAP")
public class CodeMapEntity extends JpaObjectWithDynamicFields {
    @Id
    @Column(name="CODE_ID")
    @GeneratedValue(strategy = GenerationType.AUTO,generator = "snowflake")
    @GenericGenerator(name = "snowflake",strategy = SnowflakeIdWorker.NAME)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long codeId;

    @Column(name = "CODE_NAME")
    private String codeName;

    private boolean disable = Boolean.FALSE;

    private  String description;

    @Column(name = "CODE_ITEM_LIST")
    @Convert(converter = TypedSetConverter.class)
    private Set<Long> itemList = new LinkedHashSet<>();

    @Transient
    private List<CodeMapItemEntity> items;

    public void setCodeId(final Long codeId) {
        this.codeId = codeId;
    }

    public Long getCodeId() {
        return codeId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public void setDisable(final boolean disable) {
        this.disable = disable;
    }

    public boolean isDisable() {
        return disable;
    }

    public void setCodeName(final String codeName) {
        this.codeName = codeName;
    }

    public String getCodeName() {
        return codeName;
    }

    public void setItemList(final Set<Long> itemList) {
        this.itemList = itemList;
    }

    public Set<Long> getItemList() {
        return itemList;
    }

    public void setItems(final List<CodeMapItemEntity> items) {
        this.items = items;
    }

    public List<CodeMapItemEntity> getItems() {
        return items;
    }

    @Override
    public String getIdProperty() {
        return "codeId";
    }
}
